<template>
    <div>
        <!-- 表头 -->
        <div class="Head" v-if="Head">
            <!-- 仓库名称 -->
            <div class="Cusname">
                <span style="margin-right: 10px">货品编码</span>
                <span>
                    <el-input v-model="adi.number"  placeholder="请输入货品编码"></el-input>
                </span>
            </div>
            <!-- 货架名称 -->
            <div class="Cusname">
                <span style="margin-right: 10px">货品名称</span>
                <span>
                    <el-input v-model="adi.name" placeholder="请输入货品名称"></el-input>
                </span>
            </div>
            <!-- 所属客户 -->
            <div class="Cusname">
                <span style="margin-right: 10px">所属客户</span>
                <span>
                    <el-input v-model="adi.belongName" placeholder="请输入内容" :disabled="true"> 
                        <el-button @click="dialogTableVisible = true" slot="append" >选择</el-button>
                    </el-input>
                </span>
            </div>
            <!-- 客户类别 -->
            <div class="Cusgory">
                <span style="margin-right: 10px">所属仓库</span>
                <el-select v-model="adi.wId"  placeholder="请选择仓库" style="margin-top: 10px">
                    <el-option v-for="item in ck" :key="item.wId" :label="item.name" :value="item.wId"></el-option>
                </el-select>
            </div>
            <!-- 搜索，重置按钮 -->
        </div>
            <div class="But">
                <el-button type="primary" icon="el-icon-search" @click="serch">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="Reset()">重置</el-button>
            </div>
         <!-- 表 -->
        <div class="function" style="margin-top: 20px;">
            <el-button type="warning" icon="el-icon-download" plain>导出</el-button>
            <div style="float: right">
                <el-tooltip class="item" effect="dark" content="隐藏搜索" placement="top">
                    <el-button icon="el-icon-search" circle @click="Display"></el-button>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="刷新" placement="top">
                    <el-button icon="el-icon-refresh" circle @click="Reset"></el-button>
                </el-tooltip>
            </div>
        </div>
        <el-table
            :data="tableData"
            class="content"
            :cell-style="rowClass"
            :header-cell-style="headClass"
        >
                <el-table-column label="序号" width="60" type="index" :index="indexMethod">     </el-table-column>
            <el-table-column prop="number" label="货品编码"></el-table-column>
            <el-table-column prop="name" label="货品名称"></el-table-column>
            <el-table-column prop="belongName" label="所属客户"></el-table-column>
            <el-table-column prop="stock" label="库存数量"></el-table-column>
            <el-table-column prop="category" label="货品类别"></el-table-column>
            <el-table-column prop="code" label="条形码"></el-table-column>
            <el-table-column prop="brand" label="品牌"></el-table-column>
            <el-table-column prop="spec" label="商品规格"></el-table-column>
            <el-table-column prop="validity" label="保质期"></el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="block">
            <el-pagination
                background
                style="float: right"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="adi.pageNum"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="adi.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
            >
            </el-pagination>
        </div>
        <!-- 添加内框 -->
            <el-dialog class="size" title="归属仓储客户选择" :visible.sync="dialogTableVisible">
                <el-table :data="tableDatas" class="biop">
                    <el-table-column prop="name" label="名称" width="130"></el-table-column>
                    <el-table-column prop="address" label="地址" width="150"></el-table-column>
                    <el-table-column prop="address" label="联系人" width="130"></el-table-column>
                    <el-table-column prop="phone" label="电话" width="130"></el-table-column>
                    <el-table-column prop="fax" label="传真" width="130"></el-table-column>
                    <el-table-column prop="callNumber" label="手机" width="130"></el-table-column>
                    <el-table-column label="操作" fixed="right">
                        <template slot-scope="scope">
                            <el-button @click="Choice(scope.row)">选择</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="block" style="margin-bottom: 20px; margin-top: 5px">
                    <el-pagination
                        background
                        style="float: right"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page.pageNum"
                        :page-sizes="[10, 20, 30, 50]"
                        :page-size="page.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="10"
                    >
                    </el-pagination>
                </div>
            </el-dialog>
    </div>
</template>

<script>
import {liststock,listWarehouse,listcustomer} from '../../api/user.js'
export default {
    data() {
        return {
            ck: [],
            // 表头隐藏
            Head: true,
             dialogTableVisible: false,
            value:'',
             tableData: [],
            tableDatas: [],

              // 分页
            page: {
                pageSize: 10,
                pageNum: 1
            },
            // 客户类别
            options: [
                {
                    value: '选项1',
                    label: '全部'
                },
                {
                    value: '选项2',
                    label: '仓储客户'
                },
                {
                    value: '选项3',
                    label: '销售客户'
                }
            ],
            // 添加输入框
            adi: {
                 pageSize: 10,
                pageNum: 1,
                // 地址
                address: null,
                // 类别
                category: null,
                // 条码
                code: null,
                // 联系人
                contacts: null,
                // 名称
                name: null,
                // 手机号码
                phone: null,
                number:null
            },
            total:null
        };
    },
    methods:{
         // 表头显示
        Display() {
            this.Head = !this.Head;
        },
         // 表头样式设置
        headClass() {
            return 'text-align: center;background:#F8F8F9;color:#515A6D;';
        },
        // 表格样式设置
        rowClass() {
            return 'text-align: center;';
        },
        // 分页点击
        indexMethod(index) {
            return (this.page.pageNum - 1) * this.page.pageSize + index + 1;
        },
        // 分页
        handleSizeChange(val) {
            this.page.pageSize = Number(val);
            console.log(`每页 ${val} 条`);
            this.Rean()
        },
        handleCurrentChange(val) {
            this.page.pageNum = Number(val);
            console.log(`当前页: ${val}`);
            this.Rean()
        },
         // 添加内框
        Choice(index) {
            listcustomer(this.page).then((res) => {
                this.tableDatas = res.rows;
                console.log(res);
                this.adi.belongName = index.name;
                this.adi.belong = index.cId;
                this.dialogTableVisible = false;
            });
            // this.adi.belongName = index.name;
            // this.adi.belong = index.cId;
        },
        // 表格渲染
        Rean() {
            liststock(this.page).then((a) => {
                this.tableData = a.rows;
                this.total=a.total;
                console.log(a);
            });
        },
        rean() {
            listWarehouse(this.wId).then((res) => {
                this.ck = res.rows;
                console.log(res.rows);
            });
        },
        // 搜搜
         serch() {
            liststock(this.adi).then((res) => {
                console.log(res);
                this.tableData = res.rows;
                this.total=res.total
            });
        },
       // 重置按钮
        Reset() {
            this.Rean();
            this.adi.name = undefined;
            this.adi.number = undefined;
            this.adi.belongName = undefined;
            this.adi.wId = undefined;
        },
    },
    mounted(){
        this.Rean();
        this.rean();
        this.Choice()
    }
};
</script>

<style scoped>
.Head {
    height: 50px;
}
/* 客户类别 */
.Cusgory {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusgory span {
    display: block;
    height: 100%;
    line-height: 50px;
    font-weight: 800;
    color: #606266;
    float: left;
}
/* 客户名称 */
.Cusname {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusname span {
    display: block;
    height: 100%;
    line-height: 50px;
    font-weight: 800;
    color: #606266;
    float: left;
}
/* 搜素，重置按钮 */
.But {
    height: 100%;
    /* float: left; */
}
.But button {
    margin-top: 10px;
}
</style>